package com.qzsoft.zhjd.asphalt.modules.asphaltmatch.controller;

import java.util.List;
import java.util.Map;

import com.qzsoft.jeemis.common.validator.ValidatorUtils;
import com.qzsoft.zhjd.asphalt.modules.asphaltmatch.dto.AsphaltMatchTypeListDto;
import com.qzsoft.zhjd.asphalt.modules.asphaltmatch.dto.AsphaltMatchTypeSelectDto;
import com.qzsoft.zhjd.asphalt.modules.asphaltmatch.entity.AsphaltMatchTypeEntity;
import com.qzsoft.zhjd.asphalt.modules.asphaltmatch.service.AsphaltMatchTypeService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.qzsoft.jeemis.common.utils.Result;
import com.qzsoft.zhjd.common.enums.BizCode;
import com.qzsoft.zhjd.common.utils.ResultUtils;

/**
 * @ClassName AsphaltMatchTypeController
 * @Description 级配类型控制器
 * @author linhuawei
 * @since 2021-11-22
 */
@RestController
@RequestMapping("/api/asphaltMatchType")
public class AsphaltMatchTypeController {

    @Autowired
    private AsphaltMatchTypeService asphaltMatchTypeService;

    /**
     * @Title list
     * @Description 获取级配类型列表
     * @param params 查询条件
     * @return 级配类型列表
     */
    @RequiresPermissions("api:asphaltMatchType:list")
    @GetMapping("/page")
    public Result<IPage<AsphaltMatchTypeListDto>> page(@RequestParam Map<String, Object> params) {
        IPage<AsphaltMatchTypeListDto> list = asphaltMatchTypeService.pageDto(params);
        return ResultUtils.ok(list);
    }

    /**
     * @Title listSelect
     * @Description 下拉菜单级配类型
     * @param params 查询条件
     * @return 级配类型列表
     */
    @GetMapping("/listSelect")
    public Result<List<AsphaltMatchTypeSelectDto>> listSelect(@RequestParam Map<String, Object> params) {
        List<AsphaltMatchTypeSelectDto> list = asphaltMatchTypeService.listSelect(params);
        return ResultUtils.ok(list);
    }

    /**
     * @Title: find
     * @Description: 获取级配信息
     * @param id 级配主键
     * @return 级配信息
     */
    @RequiresPermissions("api:asphaltMatchType:edit")
    @GetMapping("/find/{id}")
    public Result<AsphaltMatchTypeEntity> find(@PathVariable("id") String id) {
        AsphaltMatchTypeEntity entity = asphaltMatchTypeService.getById(id);
        if (null == entity) {
            return ResultUtils.error(BizCode.DATA_NOT_FOUND);
        }
        return ResultUtils.ok(entity);
    }

    /**
     * @Title: save
     * @Description: 添加级配信息
     * @param entity 级配信息
     * @return 添加结果
     */
    @RequiresPermissions("api:asphaltMatchType:save")
    @PostMapping("/save")
    public Result<String> save(@RequestBody AsphaltMatchTypeEntity entity) {
        ValidatorUtils.validateEntity(entity);
        asphaltMatchTypeService.save(entity);
        return ResultUtils.ok();
    }

    /**
     * @Title: save
     * @Description: 添加级配信息
     * @param entity 级配信息
     * @return 添加结果
     */
    @PostMapping("/update")
    public Result<String> update(@RequestBody AsphaltMatchTypeEntity entity) {
        ValidatorUtils.validateEntity(entity);
        asphaltMatchTypeService.updateById(entity);
        return ResultUtils.ok();
    }

    /**
     * @Title: delete
     * @Description: 删除级配信息
     * @param ids 级配主键
     * @return 删除结果
     */
    @RequiresPermissions("api:asphaltMatchType:remove")
    @PostMapping("/delete/{id}")
    public Result<String> delete(@PathVariable("id") String id) {
        asphaltMatchTypeService.removeById(id);
        return ResultUtils.ok();
    }

}
